﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DEMO_TEMP1
{
    public partial class weighloc : Form
    {
        WebPor.Service1 lc = new WebPor.Service1();
        DataSet ds = new DataSet();
        string mawb_no, userid = "";
        int dex;
        public weighloc(string user, DataSet data, int index)
        {
            InitializeComponent();
            this.ds = data;
            this.dex = index;
            this.userid = user;
            if (ds == null)
            {
                MessageBox.Show("Data Not Found");
            }
            else
            {
                mawb_no = ds.Tables[0].Rows[dex]["display_mawb"].ToString();
                // MessageBox.Show("Data  Found");
                DataTable T_B_weight = CreateTableweight(mawb_no);
                dataGrid1.DataSource = T_B_weight;
                DataTable T_Loc = CreateTableLoc(mawb_no);
                dataGrid2.DataSource = T_Loc;
                label4.Text = mawb_no;

            }
        }

        private DataTable CreateTableLoc(string mawb_no)
        {
            lc.Url = String.Format("http://192.168.1.220/WebAppPor01/Service1.asmx");
            DataSet T_L = lc.GetLocationHis(mawb_no);
            //DateTime time;
            string loc, sin, sout;
            DataTable MAWB_list = new DataTable();
          //  MAWB_list.Columns.Add("Time", typeof(DateTime));
            MAWB_list.Columns.Add("Location", typeof(string));
            MAWB_list.Columns.Add("in", typeof(string));
            MAWB_list.Columns.Add("out", typeof(string));
            ////////////////////Getdata form dataset//////////////////////////
            for (int i = 0; i < T_L.Tables[0].Rows.Count; i++)
            {
                //string t = ds.Tables[0].Rows[i]["time"].ToString().Trim();
                //DateTime.Parse(t);
               // time = T_L.Tables[0].Rows[i][""].ToString().Trim();
                loc = T_L.Tables[0].Rows[i]["location"].ToString().Trim();
                sin = T_L.Tables[0].Rows[i]["piece_count_in"].ToString().Trim();
                sout = T_L.Tables[0].Rows[i]["piece_count_out"].ToString().Trim();
                /////////////////////////////////////////////////////////////////
                MAWB_list.Rows.Add( loc, sin, sout);
            }


            //////////////set size Table////////////////////////////////////

            ////////////////////////////////////////////////////////////////
            return MAWB_list;
        }

        private DataTable CreateTableweight(string mawb)
        {
            lc.Url = String.Format("http://192.168.1.220/WebAppPor01/Service1.asmx");
            DataSet dsWeigH = new DataSet();
            dsWeigH = lc.GetweightHis(mawb);

             DataTable TW = new DataTable();
            DateTime time;
              string pcs, scl, HAWB,Flight_no,Flight_date;
            // ///////////create head column/////////////////
              TW.Columns.Add("Time", typeof(string));
              TW.Columns.Add("pcs", typeof(string));
              TW.Columns.Add("scl", typeof(string));
              TW.Columns.Add("HAWB", typeof(string));
              TW.Columns.Add("Flight no", typeof(string));
              TW.Columns.Add("Flight date", typeof(string));
            /////////////////////////////////////////////////

            // /////////Getdata for table////////////////////
             for (int i = 0; i < dsWeigH.Tables[0].Rows.Count; i++)
             {
                 string t = dsWeigH.Tables[0].Rows[i]["create_date"].ToString().Trim();
                 time = DateTime.Parse(t);
                 string t2 = string.Format("{0:dd/HH:mm}", time);
                 pcs = dsWeigH.Tables[0].Rows[i]["total_piece_count"].ToString().Trim();
                 scl = dsWeigH.Tables[0].Rows[i]["scale_id"].ToString().Trim();
                 HAWB = dsWeigH.Tables[0].Rows[i]["hawb"].ToString().Trim();

                //string timef = ds.Tables[0].Rows[i]["flight_date"].ToString().Trim();
                //DateTime dt = DateTime.Parse(timef);
                 Flight_date = dsWeigH.Tables[0].Rows[i]["display_flight_date"].ToString().Trim();
                 Flight_no = dsWeigH.Tables[0].Rows[i]["display_flight_number"].ToString().Trim();

            //     mawb_no = ds.Tables[0].Rows[i]["mawb_no"].ToString().Trim();




                 TW.Rows.Add(t2,pcs, scl, HAWB, Flight_no, Flight_date);
             }

            /////////////////////////////////////////////
             return TW;
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {

            Scanlocation Sl = new Scanlocation(userid, mawb_no, dex);
            Sl.Show();
            this.Close();


        }

       }
}